import Mock from 'mockjs'

const Random = Mock.Random

export default [
  // 获取用户列表
  {
    url: '/api/admin/users',
    method: 'get',
    response: ({ query }) => {
      const { page = 1, pageSize = 10 } = query
      const list = Array(pageSize).fill(0).map(() => ({
        id: Random.id(),
        username: Random.cname(),
        email: Random.email(),
        createTime: Random.datetime(),
        status: Random.pick([1, 0]),
        deleting: false
      }))
      
      return {
        code: 200,
        data: {
          total: 100,
          list
        },
        message: '获取用户列表成功'
      }
    }
  },

  // 删除用户
  {
    url: '/api/admin/users/\\d+',
    method: 'delete',
    response: () => {
      return {
        code: 200,
        message: '删除用户成功'
      }
    }
  },

  // 获取博客列表
  {
    url: '/api/admin/blogs',
    method: 'get',
    response: ({ query }) => {
      const { page = 1, pageSize = 10 } = query
      const list = Array(pageSize).fill(0).map(() => ({
        id: Random.id(),
        title: Random.title(),
        author: Random.cname(),
        createTime: Random.datetime(),
        status: Random.pick([1, 2, 3, 4]), // 1:已发布 2:审核中 3:未通过 4:草稿
        deleting: false
      }))
      
      return {
        code: 200,
        data: {
          total: 100,
          list
        },
        message: '获取博客列表成功'
      }
    }
  },

  // 删除博客
  {
    url: '/api/admin/blogs/\\d+',
    method: 'delete',
    response: () => {
      return {
        code: 200,
        message: '删除博客成功'
      }
    }
  }
]
